package com.alvis.media.service.impl;
import com.alvis.media.domain.User;
import com.alvis.media.domain.VideoInfo;
import com.alvis.media.domain.VideoPlay;
import com.alvis.media.repository.MediaBaseMapper;
import com.alvis.media.repository.VideoInfoMapper;
import com.alvis.media.service.VideoService;
import com.alvis.media.utility.DateTimeUtil;
import com.alvis.media.viewmodel.video.VideoPageRequestVM;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.cache.annotation.CacheEvict;
import org.springframework.stereotype.Service;

@Service
public class VideoServiceImpl extends BaseServiceImpl<VideoInfo> implements VideoService {

    private final VideoInfoMapper videoInfoMapper;
    public VideoServiceImpl(MediaBaseMapper<VideoInfo> baseMapper, VideoInfoMapper videoInfoMapper) {
        super(baseMapper);
        this.videoInfoMapper = videoInfoMapper;
    }

    @Override
    public PageInfo<VideoInfo> videoPage(VideoPageRequestVM requestVM) {
        return PageHelper.startPage(requestVM.getPageIndex(), requestVM.getPageSize(), "video_id desc").doSelectPageInfo(() ->
                videoInfoMapper.videoPage(requestVM)
        );
    }

    @Override
    public Integer queryVideoCount(VideoInfo videoInfo) {
        videoInfo.setCreateTime(DateTimeUtil.getMonthStartDay());
        return videoInfoMapper.selectNewVideoCount(videoInfo);
    }

    @Override
    public String findBestVideo(VideoPlay videoPlay) {
        return videoInfoMapper.selectBestVideo(videoPlay);
    }

    @Override
    public VideoInfo getVideoById(Integer id) {
        return videoInfoMapper.selectByPrimaryKey(id);
    }
}
